# delimit ;
clear ;
set more off ;
est drop _all ;
cd "R:/personlig/fenellac/menarche_replication/analysis/" ;

global plusdir "R:/personlig/fenellac/stata_ado/plus/" ;
sysdir set PLUS $plusdir ;
adopath ++ $plusdir ;

* **************************************************************************** ;
* This code replicates Appendix E, Table 2.
*
* Paper: "Age of Marriage and Women's Political Engagement: Evidence from India"
* Authors: Fenella Carpena, Francesca Jensenius
* 
* Code by Fenella Carpena
* Last update: March 3, 2020
* **************************************************************************** ;

****************************************************************************** ;
* select the sample
****************************************************************************** ;

use "./input/eligible-women-ihds02-lhs.dta", clear ;
merge 1:1 IDHH PERSONID using "./input/eligible-women-ihds02-rhs.dta" ;
tab _merge ;
assert _merge == 3 ;
drop _merge ;

* keep only women who are married only once (i.e., have not ever remarried) ;
drop if ever_remarried == 1 ;
  
* keep only women age of menarche between 11-18 (1st-99th pctile) ; 
summ menarche_age ;
keep if menarche_age >= 11 & menarche_age <= 18 ;

* generating district identifier ;
egen dt_id = group(STATEID DISTID) ;

****************************************************************************** ;
* label variables for the output table 
****************************************************************************** ;

local political "attended_panchayat discuss_politics member_pol_org" ;

label var attended "\shortstack[l]{Attended village \\ council meeting \\ last year}" ;
label var discuss_politics "\shortstack[l]{Discusses politics \\ and community \\ with husband}" ;
label var member_pol_org "\shortstack[l]{Participates\\ in a political \\ organization}" ;

label var marriage_age "Marriage Age" ;

****************************************************************************** ;
* TABLE: IV regressions
****************************************************************************** ;
est drop _all ;

foreach var of varlist `political' { ;

	* pooled sample ;
 	ivreghdfe `var' height_measure hindu muslim sc st obc age mother_yrs_educ father_yrs_educ ever_schooled (marriage_age = menarche_age), a(dt_id) robust ;
	est sto `var'1 ;
	estadd local sample "Full" ; 
	
	* rural sample ;
	ivreghdfe `var' height_measure hindu muslim sc st obc age mother_yrs_educ father_yrs_educ ever_schooled (marriage_age = menarche_age) if rural == 1 , a(dt_id) robust ;
	est sto `var'2 ;
	estadd local sample "Rural" ; 

	* urban sample ;
	ivreghdfe `var' height_measure hindu muslim sc st obc age mother_yrs_educ father_yrs_educ ever_schooled (marriage_age = menarche_age) if rural == 0 , a(dt_id) robust ;
	est sto `var'3 ;
	estadd local sample "Urban" ; 
	
} ;

esttab * using "./output/table-robustness-controlling-for-ever-schooled.tex",
	replace
	drop(height_measure hindu muslim sc st obc age mother_yrs_educ father_yrs_educ ever_schooled) 
	cells(b(label() star fmt(%9.3f %9.3f)) se(par)) 
	star(* 0.10 ** 0.05 *** 0.01) 
	stats(sample N, fmt(%20s %9.0f) labels("Sample" "Observations"))
	prehead(\begin{table}[h!]\centering \normalsize `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"'
		\captionsetup{justification=centering} 
		\caption{Robustness to Controlling for Ever Schooled}
		\label{table-robustness-controlling-for-ever-schooled}
		\begin{tabular*}{\hsize}{lp{1.1cm}p{1.1cm}p{1.1cm}p{1.1cm}p{1.1cm}p{1.1cm}p{1.1cm}p{1.1cm}p{1.1cm}}
		\toprule)
	nodepvars nomtitles
	legend label  booktabs  collabels( , none)
	mgroups(
	"\shortstack[c]{Attended village \\ council meeting \\ last year}"
	"\shortstack[c]{Discussess politics \\ and community \\  with husband}"
	"\shortstack[c]{Participates in \\ a political \\ organization}" 
	, pattern(1 0 0 1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
	postfoot(`"\bottomrule"'  \end{tabular*} \captionsetup{justification=justified, width=\hsize} 
		\caption*{\small \textit{Notes:} 
		This table replicates the IV regressions in Table \ref{table-IV-political}, but controls for an indicator for whether the respondent ever attended school
		as a robustness check. The first stage regression is shown in column 5 of
		Appendix Tables \ref{table-first-stage-full} (full sample), \ref{table-first-stage-rural} (rural sample), and \ref{table-first-stage-urban} (urban sample).
		Robust SEs in parenthesis. ***\$\,p < 0.01$, **\$\,p < 0.05$, *\$\,p<0.10$.\looseness=-1}
		\end{table}) ;

exit ;
